#include <iostream>
#include <fstream>
#include <vector>
#include <chrono>

void bubble_sort(std::vector<int>& arr) {
    int n = arr.size();
    for (int i = 0; i < n; i++) {
        bool swapped = false;
        for (int j = 0; j < n - i - 1; j++) {
            if (arr[j] > arr[j + 1]) {
                std::swap(arr[j], arr[j + 1]);
                swapped = true;
            }
        }
        if (!swapped) {
            break;
        }
    }
}

int main() {
    std::vector<std::string> files = {"m1_sorted.txt", "m2_reverse.txt", "m3_shuffle.txt"};
    for (const std::string& file : files) {
        std::ifstream f(file);
        std::vector<int> values;
        int x;
        while (f >> x) {
            values.push_back(x);
        }
        f.close();
        auto start_time = std::chrono::high_resolution_clock::now();
        bubble_sort(values);
        auto end_time = std::chrono::high_resolution_clock::now();
        double duration_ms = std::chrono::duration<double, std::milli>(end_time - start_time).count();
        std::cout << "Время сортировки файла " << file << ": " << std::fixed << duration_ms << " миллисекунд" << std::endl;
    }
    return 0;
}
